require 'gamifier/model'

module Gamifier
  class Player < Model

    special_attributes :email, :site
    mutable_attributes :first_name, :last_name, :nickname, :display_name, :picture_url, :admin

    module FinderMethods

      def find_by_site_and_email(site, email, params = {})
        res = engine.transmit(:get, path, :query => params.merge({:site => site, :email => email}))
        select_first_entry_if_any(res)
      end

      def find_by_player_id(player_id, params = {})
        res = engine.transmit(:get, [path, player_id].join('/'))
        select_first_entry_if_any(res)
      end

    end

    def credit(verb, metadata = {}, options = {})
      engine.activities.build(metadata.merge({:player_id => _id, :verb => verb})).save(options)
    end

  end
end
